package com.tianzeculture.stagebao.activity.artist.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.bumptech.glide.Glide;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.view.SqImageView;

import java.util.List;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/5/29 0029.
 */

public class PhotoItemAdapter extends BaseAdapter {
    Context context;
    List<String> list;

    public PhotoItemAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_artist_photo_item, null);
            holder.ivPhotoItem = view.findViewById(R.id.ivPhotoItem);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        setData(holder, i);
        return view;
    }

    private void setData(ViewHolder holder, int i) {
        Glide.with(context).load(PICTURE_URL + list.get(i)).error(R.mipmap.test).placeholder(R.mipmap.test).into(holder.ivPhotoItem);
    }

    private class ViewHolder {
        SqImageView ivPhotoItem;
    }
}